/*
 * SummaryDialog.java
 *
 * Created on June 9, 1999, 10:56 PM
 *
 * Modification Log:
 * 1.00   09th Jun 1999   Tanmay   Original version.
 * 2.00   16th Dec 2001   Tanmay   Moved over to Java Swing.
 *-----------------------------------------------------------------------------------------
 *       10th Sep 2003   Tanmay   Moved to SourceForge (http://classeditor.sourceforge.net)
 *-----------------------------------------------------------------------------------------
 */

package gui;

import guihelper.JavaFileFilter;
import java.io.*;

/**
 * Dialog to show summary of class files.
 * <br><br>
 *
 * @author 	Tanmay K. Mohapatra
 * @version     2.00, 16th December, 2001
 */
public class SummaryDialog extends javax.swing.JDialog {
    
    /** Creates new form SummaryDialog */
    public SummaryDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setClassFileSummary("Working... Please wait.");
    }
    
    public void setClassFileSummary(String sText) {
        txtSumary.setText(sText);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jScrollPane1 = new javax.swing.JScrollPane();
        txtSumary = new javax.swing.JTextArea();
        btnSaveAs = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        txtSumary.setWrapStyleWord(true);
        txtSumary.setEditable(false);
        txtSumary.setColumns(40);
        txtSumary.setTabSize(2);
        txtSumary.setRows(20);
        jScrollPane1.setViewportView(txtSumary);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(jScrollPane1, gridBagConstraints);

        btnSaveAs.setText("Save As");
        btnSaveAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveAsActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(btnSaveAs, gridBagConstraints);

        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(btnClose, gridBagConstraints);

        pack();
    }//GEN-END:initComponents
    
    private void btnSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveAsActionPerformed
        String sFileName;
        FileWriter  fileWriter;
        
        javax.swing.JFileChooser newFileChooser = new javax.swing.JFileChooser();
        newFileChooser.addChoosableFileFilter(new JavaFileFilter("html", "HTML Files"));
        newFileChooser.addChoosableFileFilter(new JavaFileFilter("doc", "Document Files"));
        newFileChooser.addChoosableFileFilter(new JavaFileFilter("txt", "Text Files"));
        int returnVal = newFileChooser.showSaveDialog(this);
        
        if(returnVal != javax.swing.JFileChooser.APPROVE_OPTION) {
            return;
        }
        
        sFileName = newFileChooser.getSelectedFile().getAbsolutePath();
        
        try {
            fileWriter = new FileWriter(sFileName, false);
            fileWriter.write(txtSumary.getText());
            fileWriter.close();
        }
        catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
            return;
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            return;
        }
    }//GEN-LAST:event_btnSaveAsActionPerformed
    
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        // Add your handling code here:
        closeDialog(null);
    }//GEN-LAST:event_btnCloseActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnSaveAs;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtSumary;
    // End of variables declaration//GEN-END:variables
    
}
